import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '仓库名称',
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: '仓库地址',
    align: 'center',
    dataIndex: 'address',
  },
  {
    title: '负责人',
    align: 'center',
    dataIndex: 'manager',
  },
  {
    title: '联系方式',
    align: 'center',
    dataIndex: 'contactPhone',
  },
  {
    title: '收费方式',
    align: 'center',
    dataIndex: 'chargeType',
    customRender: ({ text }) => {
      return render.renderDict(text, 'baseinfo_charge_type');
    },
  },
  {
    title: '价格',
    align: 'center',
    dataIndex: 'price',
  },
  {
    title: '仓库类型',
    align: 'center',
    dataIndex: 'type',
    customRender: ({ text }) => {
      return render.renderDict(text, 'baseinfo_warehouse_type');
    },
  },
  {
    title: '备注',
    align: 'center',
    dataIndex: 'remarks',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '仓库地址',
    field: 'address',
    component: 'JInput',
    colProps: { span: 6 },
  },
  {
    label: '负责人',
    field: 'manager',
    component: 'JInput',
    colProps: { span: 6 },
  },
  {
    label: '联系方式',
    field: 'contactPhone',
    component: 'JInput',
    colProps: { span: 6 },
  },
  {
    label: '仓库类型',
    field: 'type',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'baseinfo_warehouse_type',
      placeholder: '请选择仓库类型',
      stringToNumber: true,
    },
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '仓库名称',
    field: 'name',
    component: 'Input',
  },
  {
    label: '仓库地址',
    field: 'address',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入仓库地址!' }];
    },
  },
  {
    label: '负责人',
    field: 'manager',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入负责人!' }];
    },
  },
  {
    label: '联系方式',
    field: 'contactPhone',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: false }, { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' }];
    },
  },
  {
    label: '收费方式(天)',
    field: 'chargeType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'baseinfo_charge_type',
      placeholder: '请选择收费方式',
      stringToNumber: true,
    },
    dynamicRules: () => {
      return [{ required: true, message: '请选择收费方式!' }];
    },
  },
  {
    label: '价格',
    field: 'price',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入价格!' },
        { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' },
      ];
    },
  },
  {
    label: '仓库类型',
    field: 'type',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'baseinfo_warehouse_type',
      placeholder: '请选择仓库类型',
      stringToNumber: true,
    },
  },
  {
    label: '备注',
    field: 'remarks',
    component: 'InputTextArea',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: { title: '仓库名称', order: 0, view: 'text', type: 'string' },
  address: { title: '仓库地址', order: 1, view: 'text', type: 'string' },
  manager: { title: '负责人', order: 2, view: 'text', type: 'string' },
  contactPhone: { title: '联系方式', order: 3, view: 'text', type: 'string' },
  chargeType: { title: '收费方式', order: 4, view: 'number', type: 'number', dictCode: 'baseinfo_charge_type' },
  price: { title: '价格', order: 5, view: 'number', type: 'number' },
  type: { title: '仓库类型', order: 6, view: 'number', type: 'number', dictCode: 'baseinfo_warehouse_type' },
  remarks: { title: '备注', order: 7, view: 'textarea', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
